#include "mystdio.h"
#include <string.h>
#include <stdio.h>
#include <unistd.h>

#define FILE_NAME "log.txt"

int main()
{
  myFILE *fp = my_fopen(FILE_NAME, "w");
  if(fp == NULL) return 1;

  const char *str = "hello linux";
  int cnt = 10;
  char buffer[128];
  while(cnt)
  {
    // sprintf(buffer, "%s - %d\n", str, cnt); // 刷新10次
    sprintf(buffer, "%s - %d", str, cnt);      // 刷新1次
    my_write(fp, buffer, strlen(buffer));
    cnt--;
  
    sleep(1);

    my_fflush(fp); // 当没有 '\n' 时可强制刷新
  }

  my_fclose(fp);

  return 0;
}

